package cn.iotab.iotkit.transport.api.access.model.custom.firmware;

import cn.iotab.iotkit.transport.api.access.model.message.CommonDeviceMessage;
import cn.iotab.iotkit.transport.api.access.model.message.OriginMessage;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;

/**
 * 设备请求平台，拉取固件信息
 *
 * @since 1.0.3
 * @see RequestFirmwareMessageReply
 */
@Getter
@Setter
public class RequestFirmwareMessage extends CommonDeviceMessage{

    //当前设备固件版本,没有则不传
    private String currentVersion;

    //申请更新固件版本,为空则为最新版
    private String requestVersion;

    @Override
    public OriginMessage toOriginMessage() {
        throw new UnsupportedOperationException("unsupported operation for not support RequestFirmwareMessage to device");
    }

    @Override
    public void fromOriginMessage(String productKey, String deviceId, OriginMessage message) {
        super.fromOriginMessage(productKey, deviceId, message);
        JSONObject jsonObject = getJsonParam();
        this.currentVersion = jsonObject.getString("currentVersion");
        this.requestVersion = jsonObject.getString("requestVersion");
    }
}
